﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// 
    /// </summary>
    public class MeanRemoval : BaseImageFilter
    {
        protected int m_nWeight = 9;

        /// <summary>
        /// Initializes a new instance of the <see cref="MeanRemoval"/> class.
        /// </summary>
        public MeanRemoval()
            : this(9)
        {
        }

        /// <summary>
        /// Use this to specify a certain weight
        /// </summary>
        /// <param name="_nWeight"></param>
        public MeanRemoval(int _nWeight)
        {
            m_nWeight = _nWeight;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MeanRemoval"/> class.
        /// </summary>
        /// <param name="_meanRemoval">The _mean removal.</param>
        internal MeanRemoval(MeanRemoval _meanRemoval)
        {
            this.m_nWeight = _meanRemoval.m_nWeight;
        }

        /// <summary>
        /// Returns or sets the weight
        /// </summary>
        public int Weight
        {
            get { return m_nWeight; }
            set { m_nWeight = value; }
        }

        /// <summary>
        /// removes means from bitmap.
        /// </summary>
        /// <param name="_bitmap">The bitmap.</param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {    
			CConvMatrix matrix = new CConvMatrix();
			matrix.SetAll(-1);
			matrix.Pixel = m_nWeight;
			matrix.Factor = m_nWeight - 8;
            new Convolution3x3(matrix).Execute(_bitmap);
            return _bitmap;
        }

        /// <summary>
        /// Use this to return a copy of this filter.
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new MeanRemoval(this);
        }
    }
}
